package com.lee.template.service.impl;

import com.lee.template.service.AbstractPayCallbackTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zfl_a
 * @date 2020/8/12
 * @project springboot_design_pattern
 */
@Service
public class WxPayCallbackTemplate extends AbstractPayCallbackTemplate {
    @Override
    protected String fail() {
        return "微信支付失败";
    }

    @Override
    protected String success() {
        return "微信支付成功";
    }

    @Override
    protected String asyncPayResult(Map<String, String> verifySignature) {

        System.out.println("【微信支付】根据支付状态结果同步至数据库");
        //支付状态 1代表支付成功
        String payStatus = verifySignature.get("payStatus");
        if("1".equals(payStatus)) {
            //订单编号
            String orderNumber = verifySignature.get("orderNumber");
            System.out.println("【微信支付】支付成功，状态已修改，订单编号为："+orderNumber);
        }
        return success();
    }

    @Override
    protected void payLog(Map<String, String> verifySignature) {
        System.out.println("【微信支付】记录操作日志...."+verifySignature);
    }

    @Override
    protected Map<String, String> verifySignature() {

        Map<String,String> verifySignature = new HashMap<>();
        verifySignature.put("code","200");
        //1表示成功
        verifySignature.put("payStatus","1");
        verifySignature.put("orderNumber","202008120001");
        verifySignature.put("price","3699");
        verifySignature.put("desc","华为 Nova7 Pro");
        return verifySignature;
    }
}
